<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>首页</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
    }
  </style>
</head>

<body>
  <div></div>
</body>
<script>
  "use strict"; {
    function createOverLoad() {
      const callMap = new Map();

      // 重载函数
      function overload(...args) {
        let key = args.map(arg => typeof arg).join(",");
        const fn = callMap.get(key);
        if (fn) {
          return fn.apply(this, args);
        };

        throw new Error(`没有找到对应的方法了，请修改`);
      };

      /** 实现重载的方法，最后一项为函数体 */
      overload.addImpl = function (...args) {
        // 获取并弹出最后一个参数，并把该参数作为函数体
        let fn = args.pop();
        if (typeof fn !== "function") {
          throw new Error(`最后一个参数不是函数方法，请注意传入的参数数据`);
        };
        // 获取到除了最后一个参数外的所有参数
        const types = args;
        callMap.set(types.join(","), fn);
      };

      return overload;
    };

    // 重载函数
    let getUser = createOverLoad();

    getUser.addImpl(() => {
      console.log(`查询所有的用户...`);
    });

    let searchPage = (page, size = 10) => {
      console.log(`按照页码和数量查询用户`);
    };
    getUser.addImpl("number", searchPage);
    getUser.addImpl("number", "number", searchPage);

    getUser.addImpl("string", name => {
      console.log(`按照用户姓名来查找用户`);
    });

    getUser.addImpl("string", "string", () => {
      console.log(`按照用户姓名和性别来查询用户`);
    });

    getUser("好的", "男");
    getUser(100, 1000, 1000, 1000);
  };
</script>

</html>